package io.elegant

import android.content.Context
import android.content.Intent
import com.bjbyhd.api.BoyhoodAPI
import java.lang.IllegalArgumentException

private var boyhoodApi: BoyhoodAPI? = null
// 天坦开启触摸浏览方法
fun Context.startTouchExplorationForTatans() = sendBroadcast(Intent("net.tatans.talkback.action_touch_exploration_start").apply {
    putExtra(Intent.EXTRA_PACKAGE_NAME, packageName)
})
// 天坦暂停触摸浏览方法
fun Context.stopTouchExplorationForTatans() = sendBroadcast(Intent("net.tatans.talkback.action_touch_exploration_stop").apply {
    putExtra(Intent.EXTRA_PACKAGE_NAME, packageName)
})
// 解说开启触摸浏览方法
fun Context.startTouchExplorationForNirenr() = sendBroadcast(Intent("com.nirenr.talkman.ACTION_ENABLED_FEEDBACK"))
// 解说暂停触摸浏览方法
fun Context.stopTouchExplorationForNirenr() = sendBroadcast(Intent("com.nirenr.talkman.ACTION_DISENABLED_FEEDBACK"))
// 保亿开启触摸浏览方法
fun Context.startTouchExplorationForBoyhood() {
    if(boyhoodApi == null) try {
        boyhoodApi = BoyhoodAPI(this) {
            boyhoodApi?.openTouchExploration(packageName)
        }
    } catch (e: IllegalArgumentException) {
        e.printStackTrace()
    }
    boyhoodApi?.openTouchExploration(packageName)
}
// 保亿暂停触摸浏览方法
fun Context.stopTouchExplorationForBoyhood() = boyhoodApi?.pauseTouchExploration(packageName)
